﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;

namespace FACUI.BasicClass
{
    public static class StringUtil
    {
        public static string getDateTimeString()
        {
            return DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff", DateTimeFormatInfo.InvariantInfo);
        }

        public static string getDateTimeString(DateTime dt)
        {
            return dt.ToString("yyyy-MM-dd HH:mm:ss.fff", DateTimeFormatInfo.InvariantInfo);
        }

        public static int getLength4ASCII(string str)
        {
            int num = 0;
            char[] chArray = str.ToCharArray();
            for (int i = 0; i < chArray.Length; i++)
            {
                if (Convert.ToInt32(chArray[i]) > 0xff)
                {
                    num += 2;
                }
                else
                {
                    num++;
                }
            }
            return num;
        }

        public static string TrimAndPadLeft4ASCII(string str, int maxlength, char paddingchar)
        {
            int totalWidth = getLength4ASCII(str.Trim());
            totalWidth = (maxlength > totalWidth) ? (maxlength - totalWidth) : 0;
            return ("".PadLeft(totalWidth, paddingchar) + str.Trim());
        }

        public static string TrimAndPadRight4ASCII(string str, int maxlength, char paddingchar)
        {
            string str2 = str.Trim();
            int totalWidth = getLength4ASCII(str2);
            totalWidth = (maxlength > totalWidth) ? (maxlength - totalWidth) : 0;
            return (str2 + "".PadLeft(totalWidth, paddingchar));
        }
        
        public static string TrimAndPadLeft4ASCII(string str, int maxlength)
        {
            int totalWidth = getLength4ASCII(str.Trim());
            totalWidth = (maxlength > totalWidth) ? (maxlength - totalWidth) : 0;
            return ("".PadLeft(totalWidth) + str.Trim());
        }

        public static string TrimAndPadRight4ASCII(string str, int maxlength)
        {
            string str2 = str.Trim();
            int totalWidth = getLength4ASCII(str2);
            totalWidth = (maxlength > totalWidth) ? (maxlength - totalWidth) : 0;
            return (str2 + "".PadLeft(totalWidth));
        }
    }
}
